package BankAndTicket;

/**
 * @author wuhan
 * @date 2019/9/18 21:24
 */

class  Bank{
    private int sum=0;
    Object object= new Object();
    public void add(int n) throws InterruptedException {

        synchronized (object){
            sum=sum+n;
            System.out.println( Thread.currentThread().getName()+"sum="+sum);
        }

    }
}

class Cus implements Runnable{
    private Bank bank =new Bank();

    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            try {
                bank.add(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class BankDemo {
    public static void main(String[] args) {
        Cus cus = new Cus();
        Thread thread0=new Thread(cus);
        Thread thread1=new Thread(cus);
        thread0.start();
        thread1.start();

    }
}
